/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tencent.tendon.convert.json.listeners;

import com.tencent.tendon.convert.json.*;

/**
 *
 * @author nbzhang
 */
public final class JsonBoolListener extends JsonAbstractListener<Boolean> {

	private static final JsonBoolListener instance = new JsonBoolListener();

	private JsonBoolListener() {
	}

	public static JsonBoolListener getInstance() {
		return instance;
	}

	@Override
	public void convertTo(JsonWriter out, Boolean value) {
		convertBoolTo(out, value);
	}

	@Override
	public final Boolean convertFrom(final JsonReader in) {
		return convertBoolFrom(in);
	}

	@Override
	public Class<Boolean> getType() {
		return Boolean.class;
	}

	public static final class JsonBoolHexListener extends JsonAbstractListener<Boolean> {

		private static final JsonBoolHexListener instance = new JsonBoolHexListener();

		private JsonBoolHexListener() {
		}

		public static JsonBoolHexListener getInstance() {
			return instance;
		}

		@Override
		public void convertTo(JsonWriter out, Boolean value) {
			convertCharTo(out, (value == null || !value.booleanValue()) ? '0' : '1');
		}

		@Override
		public final Boolean convertFrom(final JsonReader in) {
			return convertCharFrom(in) == '1';
		}

		@Override
		public Class<Boolean> getType() {
			return Boolean.class;
		}
	}
}
